package cqut.wys.util;

import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

/**
 * --------神兽出没--------/
 * ┌─┐     ┌─┐
 * ┌─┘─┴─────┘─┴─┐
 * │      ─      │
 * │  ┬─┘   └─┬  │
 * │             │
 * │      ┴      │  Code is far away from bug with the animal protecting
 * └───┐      ┌──┘  神兽保佑,代码无bug
 * │      │
 * │      └──────┐
 * │             ├┐
 * │             ┌┘
 * └┐ ┐ ┌───┬─┐ ┌┘
 * │ ┤ ┤   │ ┤ ┤
 * └─┴─┘   └─┴─┘
 * ----------------------/
 *
 * @author wys
 * @date 2020/2/26
 */
@Component
public class Helper {

    public void processField(Object bean, String fieldStr, String newStr){
        try {
            Class clazz = bean.getClass();
            Field field = clazz.getDeclaredField(fieldStr);
            boolean accessible = field.isAccessible();
            field.setAccessible(true);
            field.set(bean, newStr);
            field.setAccessible(accessible);
        } catch (Exception ex){
            System.out.println(ex.getMessage());
        }
    }
}
